Type.registerNamespace('Dev4U.SP.PowerShell');


Dev4U.SP.PowerShell.Interpreter = function () {
    this.commands = { };
    this.outputWriter = null;

    var self = this;
    this.registerCommand('Get-Help', function () { self.outputWriter('Get-SPSite'); });
};

Dev4U.SP.PowerShell.Interpreter.prototype = {
    registerCommand: function (name, action) {
        this.commands[name] = action;
    },
    run: (function () {
        var initialized = false;

        function parseGrammar(grammar) {
            reset_all(EXEC_WEB);

            parse_grammar(grammar);

            var dfaTable = null;
            if (errors == 0) {
                undef();
                unreachable();

                if (errors == 0) {
                    first();

                    dfaTable = create_subset(nfa_states);
                    dfaTable = minimize_dfa(dfaTable);

                    lalr1_parse_table(true);
                }
            }
            return dfaTable;
        }

        return function (code) {
            if (!initialized) {
                var dfaTable = parseGrammar(this.getGrammar());
                eval(this.getDriver(dfaTable));
                initialized = true;
            }

            __parse(code);
        };
    })(),
    setOutputWriter: function (outputWriter) {
        this.outputWriter = outputWriter;
    }
};

Dev4U.SP.PowerShell.Interpreter.getInstance = (function () {
    var instance = new Dev4U.SP.PowerShell.Interpreter();

    return function () { return instance; };
})();

Dev4U.SP.PowerShell.Interpreter.registerClass('Dev4U.SP.PowerShell.Interpreter');